//
//  LBNavigationController.m
//  01.SinaWeibo
//
//  Created by Label on 12/12/15.
//  Copyright © 2015 Label. All rights reserved.
//

#import "LBNavigationController.h"

@implementation LBNavigationController

/** 类初始化方法；
 */
+ (void)initialize {
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    
    NSMutableDictionary *textAttribute = [NSMutableDictionary dictionary];
    textAttribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    textAttribute[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [item setTitleTextAttributes:textAttribute forState:UIControlStateNormal];
    
    NSMutableDictionary *textDisabledAttribute = [NSMutableDictionary dictionary];
    textDisabledAttribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    textDisabledAttribute[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [item setTitleTextAttributes:textDisabledAttribute forState:UIControlStateDisabled];
}


/** 视图控制器加载完成；
 * 基本原理：UINavigationController外观属性设置，只有在加载完成时才会有效；
 * 设计原则：视图控制器中有关视图(view)的设置，应放在其对应的视图控制器中；
 */
- (void)viewDidLoad {
        [super viewDidLoad];
        LBLog(@"NavigationController-ViewDidLoad");
}

/** 拦截压入栈的视图控制器，进行整体偏好设置；
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
        // 1. 获取根视图控制器以外的视图控制器;
        if ( self.viewControllers.count>0 ) {
                // 1.1 配置视图控制器的LeftBarButtonItem;
                viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(gotoLastViewController) Image:@"navigationbar_back" HighLightedImage:@"navigationbar_back_highlighted"];
                // 1.2 配置视图控制器的RightBarButtonItem;
                viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(gotoRootViewController) Image:@"navigationbar_more" HighLightedImage:@"navigationbar_more_highlighted"];
                // 1.3 压栈时隐藏底部工具栏;
                [viewController setHidesBottomBarWhenPushed:YES];
        }
        // 2. 调用父类压栈方法进行压栈;
        [super pushViewController:viewController animated:animated];
}

/** 返回上一级视图控制器；
 */
- (void)gotoLastViewController {
    [self popViewControllerAnimated:YES];
}

/** 返回根视图控制器；
 */
- (void)gotoRootViewController {
    [self popToRootViewControllerAnimated:YES];
}

@end
